home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Universal / Interfaces / AIncludes / Threads.a < prev    next >
Encoding:
Text File  |  1997-08-12  |  10.7 KB  |  403 lines  |  [TEXT/MPS ]

  1. ;
  2. ;    File:        Threads.a
  3. ;
  4. ;    Contains:    Thread Manager Interfaces.
  5. ;
  6. ;    Version:    Technology:    System 7.5
  7. ;                Release:    Universal Interfaces 3.0.1
  8. ;
  9. ;    Copyright:    © 1991-1997 by Apple Computer, Inc., all rights reserved.
  10. ;
  11. ;    Bugs?:        Please include the the file and version information (from above) with
  12. ;                the problem description.  Developers belonging to one of the Apple
  13. ;                developer programs can submit bug reports to:
  14. ;
  15. ;                    devsupport@apple.com
  16. ;
  17. ;
  18.     IF &TYPE('__THREADS__') = 'UNDEFINED' THEN
  19. __THREADS__ SET 1
  20.  
  21.     IF &TYPE('__TYPES__') = 'UNDEFINED' THEN
  22.     include 'Types.a'
  23.     ENDIF
  24.     IF &TYPE('__MIXEDMODE__') = 'UNDEFINED' THEN
  25.     include 'MixedMode.a'
  26.     ENDIF
  27.     IF &TYPE('__ERRORS__') = 'UNDEFINED' THEN
  28.     include 'Errors.a'
  29.     ENDIF
  30.  
  31. ;  Thread states 
  32. ; typedef unsigned short                 ThreadState
  33.  
  34.  
  35. kReadyThreadState                EQU        0
  36. kStoppedThreadState                EQU        1
  37. kRunningThreadState                EQU        2
  38. ;  Error codes have been meoved to Errors.(pah) 
  39. ;  Thread environment characteristics 
  40. ; typedef void *                        ThreadTaskRef
  41.  
  42. ;  Thread characteristics 
  43. ; typedef unsigned long                 ThreadStyle
  44.  
  45.  
  46. kCooperativeThread                EQU        $00000001
  47. kPreemptiveThread                EQU        $00000002
  48. ;  Thread identifiers 
  49. ; typedef unsigned long                 ThreadID
  50.  
  51.  
  52. kNoThreadID                        EQU        0
  53. kCurrentThreadID                EQU        1
  54. kApplicationThreadID            EQU        2
  55. ;  Options when creating a thread 
  56. ; typedef unsigned long                 ThreadOptions
  57.  
  58.  
  59. kNewSuspend                        EQU        $01
  60. kUsePremadeThread                EQU        $02
  61. kCreateIfNeeded                    EQU        $04
  62. kFPUNotNeeded                    EQU        $08
  63. kExactMatchThread                EQU        $10
  64. ;  Information supplied to the custom scheduler 
  65. SchedulerInfoRec        RECORD 0
  66. InfoRecSize                 ds.l    1                ; offset: $0 (0)
  67. CurrentThreadID             ds.l    1                ; offset: $4 (4)
  68. SuggestedThreadID         ds.l    1                ; offset: $8 (8)
  69. InterruptedCoopThreadID     ds.l    1                ; offset: $C (12)
  70. sizeof                     EQU *                    ; size:   $10 (16)
  71.                         ENDR
  72. ; typedef struct SchedulerInfoRec *        SchedulerInfoRecPtr
  73.  
  74.  
  75.     IF TARGET_CPU_68K ** TARGET_RT_MAC_CFM THEN
  76. ;    The following UniversalProcPtrs are for CFM-68k compatiblity with
  77. ;    the implementation of the Thread Manager.
  78. ;
  79.  
  80. ; typedef UniversalProcPtr                 ThreadEntryProcPtr
  81.  
  82. ; typedef UniversalProcPtr                 ThreadSchedulerProcPtr
  83.  
  84. ; typedef UniversalProcPtr                 ThreadSwitchProcPtr
  85.  
  86. ; typedef UniversalProcPtr                 ThreadTerminationProcPtr
  87.  
  88. ; typedef UniversalProcPtr                 DebuggerNewThreadProcPtr
  89.  
  90. ; typedef UniversalProcPtr                 DebuggerDisposeThreadProcPtr
  91.  
  92. ; typedef UniversalProcPtr                 DebuggerThreadSchedulerProcPtr
  93.  
  94.     ELSE
  95. ;    The following ProcPtrs cannot be interchanged with UniversalProcPtrs because
  96. ;    of differences between 680x0 and PowerPC runtime architectures with regard to
  97. ;    the implementation of the Thread Manager.
  98.  
  99. ;  Prototype for thread's entry (main) routine 
  100. ; typedef void *                        voidPtr
  101.  
  102. ;  Prototype for custom thread scheduler routine 
  103. ;  Prototype for custom thread switcher routine 
  104. ;  Prototype for thread termination notification routine 
  105. ;  Prototype for debugger NewThread notification 
  106. ;  Prototype for debugger DisposeThread notification 
  107. ;  Prototype for debugger schedule notification 
  108.     ENDIF
  109.  
  110. ;  Thread Manager routines 
  111. ;
  112. ; pascal OSErr CreateThreadPool(ThreadStyle threadStyle, short numToCreate, Size stackSize)
  113. ;
  114.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  115.         Macro
  116.         _CreateThreadPool
  117.             move.w              #$0501,D0
  118.             dc.w                $ABF2
  119.         EndM
  120.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  121.         IMPORT_CFM_FUNCTION CreateThreadPool
  122.     ENDIF
  123.  
  124. ;
  125. ; pascal OSErr GetFreeThreadCount(ThreadStyle threadStyle, short *freeCount)
  126. ;
  127.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  128.         Macro
  129.         _GetFreeThreadCount
  130.             move.w              #$0402,D0
  131.             dc.w                $ABF2
  132.         EndM
  133.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  134.         IMPORT_CFM_FUNCTION GetFreeThreadCount
  135.     ENDIF
  136.  
  137. ;
  138. ; pascal OSErr GetSpecificFreeThreadCount(ThreadStyle threadStyle, Size stackSize, short *freeCount)
  139. ;
  140.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  141.         Macro
  142.         _GetSpecificFreeThreadCount
  143.             move.w              #$0615,D0
  144.             dc.w                $ABF2
  145.         EndM
  146.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  147.         IMPORT_CFM_FUNCTION GetSpecificFreeThreadCount
  148.     ENDIF
  149.  
  150. ;
  151. ; pascal OSErr GetDefaultThreadStackSize(ThreadStyle threadStyle, Size *stackSize)
  152. ;
  153.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  154.         Macro
  155.         _GetDefaultThreadStackSize
  156.             move.w              #$0413,D0
  157.             dc.w                $ABF2
  158.         EndM
  159.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  160.         IMPORT_CFM_FUNCTION GetDefaultThreadStackSize
  161.     ENDIF
  162.  
  163. ;
  164. ; pascal OSErr ThreadCurrentStackSpace(ThreadID thread, unsigned long *freeStack)
  165. ;
  166.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  167.         Macro
  168.         _ThreadCurrentStackSpace
  169.             move.w              #$0414,D0
  170.             dc.w                $ABF2
  171.         EndM
  172.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  173.         IMPORT_CFM_FUNCTION ThreadCurrentStackSpace
  174.     ENDIF
  175.  
  176. ;
  177. ; pascal OSErr NewThread(ThreadStyle threadStyle, ThreadEntryProcPtr threadEntry, void *threadParam, Size stackSize, ThreadOptions options, void **threadResult, ThreadID *threadMade)
  178. ;
  179.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  180.         Macro
  181.         _NewThread
  182.             move.w              #$0E03,D0
  183.             dc.w                $ABF2
  184.         EndM
  185.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  186.         IMPORT_CFM_FUNCTION NewThread
  187.     ENDIF
  188.  
  189. ;
  190. ; pascal OSErr DisposeThread(ThreadID threadToDump, void *threadResult, Boolean recycleThread)
  191. ;
  192.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  193.         Macro
  194.         _DisposeThread
  195.             move.w              #$0504,D0
  196.             dc.w                $ABF2
  197.         EndM
  198.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  199.         IMPORT_CFM_FUNCTION DisposeThread
  200.     ENDIF
  201.  
  202. ;
  203. ; pascal OSErr YieldToThread(ThreadID suggestedThread)
  204. ;
  205.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  206.         Macro
  207.         _YieldToThread
  208.             move.w              #$0205,D0
  209.             dc.w                $ABF2
  210.         EndM
  211.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  212.         IMPORT_CFM_FUNCTION YieldToThread
  213.     ENDIF
  214.  
  215. ;
  216. ; pascal OSErr YieldToAnyThread(void )
  217. ;
  218.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  219.         Macro
  220.         _YieldToAnyThread
  221.             clr.l               -(sp)
  222.             move.w              #$0205,D0
  223.             dc.w                $ABF2
  224.         EndM
  225.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  226.         IMPORT_CFM_FUNCTION YieldToAnyThread
  227.     ENDIF
  228.  
  229. ;
  230. ; pascal OSErr GetCurrentThread(ThreadID *currentThreadID)
  231. ;
  232.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  233.         Macro
  234.         _GetCurrentThread
  235.             move.w              #$0206,D0
  236.             dc.w                $ABF2
  237.         EndM
  238.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  239.         IMPORT_CFM_FUNCTION GetCurrentThread
  240.     ENDIF
  241.  
  242. ;
  243. ; pascal OSErr GetThreadState(ThreadID threadToGet, ThreadState *threadState)
  244. ;
  245.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  246.         Macro
  247.         _GetThreadState
  248.             move.w              #$0407,D0
  249.             dc.w                $ABF2
  250.         EndM
  251.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  252.         IMPORT_CFM_FUNCTION GetThreadState
  253.     ENDIF
  254.  
  255. ;
  256. ; pascal OSErr SetThreadState(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
  257. ;
  258.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  259.         Macro
  260.         _SetThreadState
  261.             move.w              #$0508,D0
  262.             dc.w                $ABF2
  263.         EndM
  264.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  265.         IMPORT_CFM_FUNCTION SetThreadState
  266.     ENDIF
  267.  
  268. ;
  269. ; pascal OSErr SetThreadStateEndCritical(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
  270. ;
  271.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  272.         Macro
  273.         _SetThreadStateEndCritical
  274.             move.w              #$0512,D0
  275.             dc.w                $ABF2
  276.         EndM
  277.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  278.         IMPORT_CFM_FUNCTION SetThreadStateEndCritical
  279.     ENDIF
  280.  
  281. ;
  282. ; pascal OSErr SetThreadScheduler(ThreadSchedulerProcPtr threadScheduler)
  283. ;
  284.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  285.         Macro
  286.         _SetThreadScheduler
  287.             move.w              #$0209,D0
  288.             dc.w                $ABF2
  289.         EndM
  290.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  291.         IMPORT_CFM_FUNCTION SetThreadScheduler
  292.     ENDIF
  293.  
  294. ;
  295. ; pascal OSErr SetThreadSwitcher(ThreadID thread, ThreadSwitchProcPtr threadSwitcher, void *switchProcParam, Boolean inOrOut)
  296. ;
  297.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  298.         Macro
  299.         _SetThreadSwitcher
  300.             move.w              #$070A,D0
  301.             dc.w                $ABF2
  302.         EndM
  303.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  304.         IMPORT_CFM_FUNCTION SetThreadSwitcher
  305.     ENDIF
  306.  
  307. ;
  308. ; pascal OSErr SetThreadTerminator(ThreadID thread, ThreadTerminationProcPtr threadTerminator, void *terminationProcParam)
  309. ;
  310.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  311.         Macro
  312.         _SetThreadTerminator
  313.             move.w              #$0611,D0
  314.             dc.w                $ABF2
  315.         EndM
  316.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  317.         IMPORT_CFM_FUNCTION SetThreadTerminator
  318.     ENDIF
  319.  
  320. ;
  321. ; pascal OSErr ThreadBeginCritical(void )
  322. ;
  323.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  324.         Macro
  325.         _ThreadBeginCritical
  326.             move.w              #$000B,D0
  327.             dc.w                $ABF2
  328.         EndM
  329.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  330.         IMPORT_CFM_FUNCTION ThreadBeginCritical
  331.     ENDIF
  332.  
  333. ;
  334. ; pascal OSErr ThreadEndCritical(void )
  335. ;
  336.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  337.         Macro
  338.         _ThreadEndCritical
  339.             move.w              #$000C,D0
  340.             dc.w                $ABF2
  341.         EndM
  342.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  343.         IMPORT_CFM_FUNCTION ThreadEndCritical
  344.     ENDIF
  345.  
  346. ;
  347. ; pascal OSErr SetDebuggerNotificationProcs(DebuggerNewThreadProcPtr notifyNewThread, DebuggerDisposeThreadProcPtr notifyDisposeThread, DebuggerThreadSchedulerProcPtr notifyThreadScheduler)
  348. ;
  349.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  350.         Macro
  351.         _SetDebuggerNotificationProcs
  352.             move.w              #$060D,D0
  353.             dc.w                $ABF2
  354.         EndM
  355.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  356.         IMPORT_CFM_FUNCTION SetDebuggerNotificationProcs
  357.     ENDIF
  358.  
  359. ;
  360. ; pascal OSErr GetThreadCurrentTaskRef(ThreadTaskRef *threadTRef)
  361. ;
  362.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  363.         Macro
  364.         _GetThreadCurrentTaskRef
  365.             move.w              #$020E,D0
  366.             dc.w                $ABF2
  367.         EndM
  368.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  369.         IMPORT_CFM_FUNCTION GetThreadCurrentTaskRef
  370.     ENDIF
  371.  
  372. ;
  373. ; pascal OSErr GetThreadStateGivenTaskRef(ThreadTaskRef threadTRef, ThreadID threadToGet, ThreadState *threadState)
  374. ;
  375.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  376.         Macro
  377.         _GetThreadStateGivenTaskRef
  378.             move.w              #$060F,D0
  379.             dc.w                $ABF2
  380.         EndM
  381.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  382.         IMPORT_CFM_FUNCTION GetThreadStateGivenTaskRef
  383.     ENDIF
  384.  
  385. ;
  386. ; pascal OSErr SetThreadReadyGivenTaskRef(ThreadTaskRef threadTRef, ThreadID threadToSet)
  387. ;
  388.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  389.         Macro
  390.         _SetThreadReadyGivenTaskRef
  391.             move.w              #$0410,D0
  392.             dc.w                $ABF2
  393.         EndM
  394.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  395.         IMPORT_CFM_FUNCTION SetThreadReadyGivenTaskRef
  396.     ENDIF
  397.  
  398.     ENDIF ; __THREADS__ 
  399.  
  400.